var express = require('express');
var router = express.Router();
var userDao = require('../dao/user/userDao');

var sessionLog = require('./sessionLog');   //验证session


/* 登录 */
router.get('/login',function(req,res,next){
    res.render('user/login.html', { title: '登录', result:[]});
});
router.post('/login',function(req,res,next){
    userDao.login(req, res, next);
});
/* 退出登录 */
router.get('/logout',function(req,res,next){
    delete req.session.user;
    res.render('user/login.html', { title: '登录', result:[]});
});

/* 添加用户 */
router.get('/add', function(req, res, next) {
    res.render('user/userAdd.html', { title: '添加用户', result:[]});
});

router.post('/add',function(req,res,next){
    userDao.add(req, res, next);
});

/* 修改用户 */
router.get('/edit', sessionLog, function(req, res, next) {
    userDao.editId(req, res, next);
});
/* 修改用户 */
router.post('/edit', sessionLog, function(req, res, next) {
    userDao.edit(req, res, next);
});

/* 删除用户 */
router.get('/del', sessionLog, function(req,res,next){
    userDao.del(req, res, next);
});

/* 查找用户 */
router.get('/findId', sessionLog, function(req,res,next){
    userDao.findId(req,res,next)
});

/* 所有用户 */
router.get('/list', sessionLog, function(req,res,next){
    userDao.list(req,res,next)
});



module.exports = router;
